import { Service } from "common/static/index";
import { Receivement, ReceivementAccount } from "entities";

export class AccountService extends Service {
    private url(path: string): string {
        return `/AdminAccount/${path}`;
    }
    offlinePayOrder(orderId: string, userId: string, paymentType: 'weixin' | 'alipay', amount: number) {
        let url = this.url('Account/OfflinePayOrder');
        return this.put(url, { orderId, userId, paymentType, amount });
    }
    /**
     * 创建收款记录
     */
    createReceivement(orderId: string, amount: number, accountId: string) {
        let receivement: Receivement = {
            Id: orderId,
            Amount: amount,
            AccountId: accountId,
        }
        let url = this.url('Account/CreateReceivement');
        return this.postByJson(url, { orderId, receivement });
    }
    async receivementAccountList() {
        let url = this.url('Account/ReceivementAccountList');
        let result = await this.get<ReceivementAccount[]>(url);
        return result;
    }
    saveReceivementAccount(account: ReceivementAccount) {
        let url = this.url('Account/SaveReceivementAccount');
        return this.postByJson(url, { model: account });
    }
    createBill(userId: string, amount: number) {
        let url = this.url(`Account/CreateBill`);
        return this.postByJson<{ Id: string }>(url, { userId, amount });
    }
    recharge(userId: string, billId: string, receivementAccountId): Promise<{ Balance: number }> {
        let url = this.url('Account/Recharge');
        return this.post(url, { userId, billId, receivementAccountId });
    }
}